package com.zhouwr.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zhouwr.common.core.aspect.annotation.AutoLog;
import com.zhouwr.common.core.vo.Query;
import com.zhouwr.common.core.vo.Result;
import com.zhouwr.system.entity.DepartRolePermissionEntity;
import com.zhouwr.system.service.DepartRolePermissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 部门角色权限表
 *
 * @author zhouwr
 * @email 1551541860@qq.com
 * @date 2020-10-08 15:53:25
 */
@Slf4j
@Api(tags = "部门角色权限表")
@RestController
@RequestMapping("system/departrolepermission")
public class DepartRolePermissionController {
    @Autowired
    private DepartRolePermissionService departRolePermissionService;

    /**
     * 分页列表查询-部门角色权限表
     *
     * @param params 分页查询参数
     * @return Result<IPage < DepartRolePermissionEntity>>
     */
    @AutoLog(value = "分页列表查询-部门角色权限表")
    @ApiOperation(value = "分页列表查询-部门角色权限表" , notes = "分页列表查询-部门角色权限表")
    @RequestMapping("/list")
    // @RequiresPermissions("system:departrolepermission:list")
    public Result<IPage<DepartRolePermissionEntity>> list(@RequestParam Map<String, Object> params) {
        IPage<DepartRolePermissionEntity> page = departRolePermissionService.page(new Query<DepartRolePermissionEntity>().getPage(params), new QueryWrapper<DepartRolePermissionEntity>());
        return Result.ok(page, "分页查询成功！");
    }


    /**
     * 根据id获取-部门角色权限表
     *
     * @param id
     * @return Result<DepartRolePermissionEntity>
     */
    @AutoLog(value = "根据id获取-部门角色权限表")
    @ApiOperation(value = "根据id获取-部门角色权限表" , notes = "根据id获取-部门角色权限表")
    @RequestMapping("/get/{id}")
    // @RequiresPermissions("system:departrolepermission:info")
    public Result<DepartRolePermissionEntity> info(@PathVariable("id") String id) {
        DepartRolePermissionEntity departRolePermission = departRolePermissionService.getById(id);
        return Result.ok(departRolePermission, "部门角色权限表" + "信息获取" + (departRolePermission != null ? "成功" : "失败"));
    }

    /**
     * 保存-部门角色权限表
     *
     * @param departRolePermission
     * @return Result<?>
     */
    @AutoLog(value = "保存-部门角色权限表")
    @ApiOperation(value = "保存-部门角色权限表" , notes = "保存-部门角色权限表")
    @RequestMapping("/save")
    // @RequiresPermissions("system:departrolepermission:save")
    public Result<?> save(@RequestBody DepartRolePermissionEntity departRolePermission) {
        boolean b = departRolePermissionService.save(departRolePermission);
        return Result.ok(b, "部门角色权限表" + "信息保存" + (b ? "成功" : "失败"));
    }

    /**
     * 修改-部门角色权限表
     *
     * @param departRolePermission
     * @return Result</ ?>
     */
    @AutoLog(value = "修改-部门角色权限表")
    @ApiOperation(value = "修改-部门角色权限表" , notes = "修改-部门角色权限表")
    @RequestMapping("/update")
    // @RequiresPermissions("system:departrolepermission:update")
    public Result<?> update(@RequestBody DepartRolePermissionEntity departRolePermission) {
        boolean b = departRolePermissionService.updateById(departRolePermission);
        return Result.ok(b, "部门角色权限表" + "信息修改" + (b ? "成功" : "失败"));
    }

    /**
     * 删除-部门角色权限表
     *
     * @param ids 主键数组
     * @return Result<?>
     */
    @AutoLog(value = "删除-部门角色权限表")
    @ApiOperation(value = "删除-部门角色权限表" , notes = "删除-部门角色权限表")
    @RequestMapping("/delete")
    // @RequiresPermissions("system:departrolepermission:delete")
    public Result<?> delete(@RequestBody String[] ids) {
        boolean b = departRolePermissionService.removeByIds(Arrays.asList(ids));
        return Result.ok(b, "部门角色权限表" + "信息删除" + (b ? "成功" : "失败"));
    }

}
